package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.entity.info.InfoRoot;
import com.clas.liu.myapplication.model.entity.user.UserRoot;
import com.clas.liu.myapplication.model.event.UserInfoEvent;
import com.clas.liu.myapplication.model.impl.UserInfoModel;
import com.clas.liu.myapplication.presenter.i.IUserInfoPresenter;
import com.clas.liu.myapplication.view.activity.impl.UserInfoActivity;

/**
 * Created by liu on 2019/5/6.
 */

public class UserInfoPresenter extends BasePresenter<UserInfoActivity, UserInfoModel> implements IUserInfoPresenter {

    public UserInfoPresenter(UserInfoActivity view) {
        super(view);
    }

    @Override
    public void getUser(int userId) {
        mModel.getUser(userId);
    }

    @Override
    public void getInfo(int userId, int type, int page_no, int page_size) {
        mModel.getInfo(userId, type, page_no, page_size);
    }

    @Override
    public void jubaoInfo(int userId) {

    }

    @Override
    protected UserInfoModel getModel(Handler handler) {
        return new UserInfoModel(handler);
    }

    @Override
    protected void eventReceive(Message msg) {
        switch (msg.what) {
            case UserInfoEvent.GET_USER_INFO_INFO_OK:
                mView.infoReturn(((UserInfoEvent) msg.obj).getInfoRoot());
                break;
            case UserInfoEvent.GET_USER_INFO_INFO_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case UserInfoEvent.GET_USER_INFO_USER_OK:
                mView.userReturn(((UserInfoEvent) msg.obj).getUserRoot());
                break;
            case UserInfoEvent.GET_USER_INFO_USER_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case UserInfoEvent.JUBAO_USER_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case UserInfoEvent.JUBAO_USER_OK:
                mView.jubaoReturn();
                break;

        }
    }
}
